﻿using System;
using System.Windows;

namespace GameLogic.Logic
{
	// Providing basic 2d vector functionality
    public class Vector2D
	{
		public double X { get; set; }
		public double Y { get; set; }

        #region Constructors
        public Vector2D(double x, double y)
		{
			this.X = x;
			this.Y = y;
		}

		public Vector2D()
			: this(0.0d, 0.0d)
		{
		}
        #endregion

		#region  Vector Operators
		public static Vector2D operator +(Vector2D v1, Vector2D v2)
		{
			return new Vector2D(v1.X + v2.X, v1.Y + v2.Y);
		}

		public static Vector2D operator +(Vector2D v1, Point p)
		{
			return new Vector2D(v1.X + p.X, v1.Y + p.Y);
		}

		public static Vector2D operator -(Vector2D v1, Vector2D v2)
		{
			return new Vector2D(v1.X - v2.X, v1.Y - v2.Y);
		}

		public static Vector2D operator -(Vector2D v1, Point p)
		{
			return new Vector2D(v1.X - p.X, v1.Y - p.Y);
		}

		public static Vector2D operator /(Vector2D v1, double d)
		{
			return new Vector2D(v1.X / d, v1.Y / d);
		}

		public static Vector2D operator *(Vector2D v1, double m)
		{
			return new Vector2D(v1.X * m, v1.Y * m);
		}
		#endregion

        #region Additional Methods
        public double Length
		{
			get { return Math.Sqrt(this.X * this.X + this.Y * this.Y); }
		}

		public void Normalize()
		{
			double length = this.Length;
			this.X /= length;
			this.Y /= length;
        }
        #endregion
    }
}
